package com.cbd.controller;

import com.cbd.dto.QueryLogDto;
import com.cbd.entity.OpLogEntity;
import com.cbd.service.impl.OpLogServiceImpl;
import com.cbd.util.ResultResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author BingBing
 * @desc  日志操作控制器类
 * @date 2024/11/26 11:25
 */
@RestController
@Slf4j
@RequestMapping("/rabbitMQ")
@Api(tags = "日志操作接口")
public class OpLogController {

    @Resource
    OpLogServiceImpl opLogService;

    /**
     * 日志查询操作
     * @param queryLogDto 查询条件类
     * @return 日志列表
     */
    @PostMapping("/queryLog")
    @ApiOperation(value = "日志查询操作", notes = "日志查询操作")
    public ResultResponse<List<OpLogEntity>> queryLog(
            @ApiParam(name = "queryLogDto", value = "查询条件类", required = false)
            @RequestBody QueryLogDto queryLogDto) {
        log.info("日志查询操作:{}", queryLogDto);
        List<OpLogEntity> list = opLogService.queryByCondition(queryLogDto);
        log.info("日志查询操作:{}", list);
        return ResultResponse.success(list);
    }

    /**
     * 获取日志总页数
     * return 日志总页数
     */
    @PostMapping ("/getLogPageCount")
    @ApiOperation(value = "获取日志总页数", notes = "获取日志总页数")
    public ResultResponse<Integer> getLogPageCount(
            @ApiParam(name = "queryLogDto", value = "查询条件类", required = false)
            @RequestBody QueryLogDto queryLogDto) {
        int count = opLogService.getPageCount(queryLogDto);
        log.info("获取日志总页数:{}", count);
        return ResultResponse.success(count);
    }
}
